#pragma once
#include <iostream>
#include "Protocol.hpp"

class Calculator
{
public:
    Calculator()
    {
    }
    Response Excute(const Request &req)
    {
        Response res;
        switch (req.Oper())
        {
        case '+':
        {
            res.SetResult(req.X() + req.Y());
            break;
        }
        case '-':
        {
            res.SetResult(req.X() - req.Y());
            break;
        }
        case '*':
        {
            res.SetResult(req.X() * req.Y());
            break;
        }
        case '/':
        {
            if (req.Y() == 0)
            {
                res.SetCode(1); // 错误码1为除0
            }
            else
            {
                res.SetResult(req.X() / req.Y());
            }
            break;
        }
        case '%':
        {
            if (req.Y() == 0)
            {
                res.SetCode(2); // 错误码2为模0
            }
            else
            {
                res.SetResult(req.X() % req.Y());
            }
            break;
        }
        default:
        {
            res.SetCode(3); // 错误码3为传的符号无法识别
            break;
        }
        }
        return res;
    }
    ~Calculator()
    {
    }
};